/********************************************
*
*
*
*  test_DosMem.c
*
*
********************************************/


#ifdef __cplusplus
 #if __cplusplus
  extern "C"{
 #endif
#endif /* __cplusplus */


#include "test_suite.h"
#include "d_dosmem.h"
#include "d_tick.h"



extern VOID ShowUsedCpuTick(VOID);




UINT32 TEST_UT_DMS_DosMemAlloc_00()
{

    return DMS_OK;
}

UINT32 TEST_UT_DMS_DosMemAlloc_01()
{

    return DMS_OK;
}

UINT32 TEST_UT_DMS_DosMemAlloc_02()
{

    return DMS_OK;
}

UINT32 TEST_UT_DMS_DosMemAlloc_03()
{

    return DMS_OK;
}

UINT32 TEST_UT_DMS_DosMemFree_00()
{

    return DMS_OK;
}

UINT32 TEST_UT_DMS_DosMemFree_01()
{

    return DMS_OK;
}

UINT32 TEST_UT_DMS_DosMemFree_02()
{

    return DMS_OK;
}

UINT32 TEST_UT_DMS_DosMemFree_03()
{

    return DMS_OK;
}

UINT32 TEST_ST_DMS_DosMemSt_00()
{
    UINT32 *pData;
    UINT32 ulRet;

    ShowUsedCpuTick();
    pData = (UINT32 *)DMS_DosMemAlloc(123);
    ShowUsedCpuTick();

    TEST_ASSERT_UEQUAL(NULL , pData );

    ShowUsedCpuTick();
    ulRet = DMS_DosMemFree((VOID *)pData);
    ShowUsedCpuTick();

    TEST_ASSERT_EQUAL(DMS_OK , ulRet);

    return DMS_OK;
}

UINT32 Test_DosmemCountNum = 0;

UINT32 TEST_ST_DMS_DosMemSt_01()
{
    UINT32 j;
    UINT32 uil;
    CHAR * pString[10240] = {NULL};

    for( uil = 0 ; uil < 10240 ; uil++ )
    {
        j = rand()%0xffff;
        pString[uil] = (CHAR * ) DMS_DosMemAlloc(j);

        if(NULL != pString[uil])
        {
            DMS_MemSet((VOID *)pString[uil] , rand() & 0xff , j );
            Test_DosmemCountNum++;
        }
    }

    for( uil = 0 ; uil < 10240 ; uil++ )
    {
        if(NULL != pString[uil])
        {
            TEST_ASSERT_EQUAL(DMS_OK , DMS_DosMemFree( (VOID *)pString[uil]) );
        }
    }

    return DMS_OK;
}

extern DosMemCtl * pstDosMemCtl;

UINT32 TEST_ST_DMS_DosMemSt_02()
{
    UINT32 i = 0xFF;

    while(i--)
    {
        TEST_ST_DMS_DosMemSt_01();
    }

    TEST_ASSERT_EQUAL( 0 , pstDosMemCtl->ulUsedSize);

    printf(" Used Size %u\n",pstDosMemCtl->ulUsedSize);

    printf("Test_DosmemCountNum %u\n",Test_DosmemCountNum);

    return DMS_OK;
}

UINT32 TEST_ST_DMS_DosMemSt_03()
{

    return DMS_OK;
}

VOID TEST_UT_DMS_DosMemAlloc()
{
    TEST_ASSERT_EQUAL(TEST_UT_DMS_DosMemAlloc_00(),DMS_OK);
    TEST_ASSERT_EQUAL(TEST_UT_DMS_DosMemAlloc_01(),DMS_OK);
    TEST_ASSERT_EQUAL(TEST_UT_DMS_DosMemAlloc_02(),DMS_OK);
    TEST_ASSERT_EQUAL(TEST_UT_DMS_DosMemAlloc_03(),DMS_OK);
}


VOID TEST_UT_DMS_DosMemFree()
{
    TEST_ASSERT_EQUAL(TEST_UT_DMS_DosMemFree_00(),DMS_OK);
    TEST_ASSERT_EQUAL(TEST_UT_DMS_DosMemFree_01(),DMS_OK);
    TEST_ASSERT_EQUAL(TEST_UT_DMS_DosMemFree_02(),DMS_OK);
    TEST_ASSERT_EQUAL(TEST_UT_DMS_DosMemFree_03(),DMS_OK);
}


VOID TEST_ST_DMS_DosMemSt()
{
    TEST_ASSERT_EQUAL(TEST_ST_DMS_DosMemSt_00(),DMS_OK);
    TEST_ASSERT_EQUAL(TEST_ST_DMS_DosMemSt_01(),DMS_OK);
    TEST_ASSERT_EQUAL(TEST_ST_DMS_DosMemSt_02(),DMS_OK);
    TEST_ASSERT_EQUAL(TEST_ST_DMS_DosMemSt_03(),DMS_OK);
}

VOID TEST_suite_DosMem(VOID)
{
    CU_pSuite suite;
    suite = CU_add_suite(__FUNCTION__, NULL, NULL);
    CU_ADD_TEST(suite, TEST_UT_DMS_DosMemAlloc);
    CU_ADD_TEST(suite, TEST_UT_DMS_DosMemFree);
    CU_ADD_TEST(suite, TEST_ST_DMS_DosMemSt);
}

#ifdef __cplusplus
 #if __cplusplus
  }
 #endif
#endif /* __cplusplus */
